﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Read.Api.Application.Command.Processiings_OneWay;
using Traceability_Management.Read.Api.Application.Command.Processiings_TwoWay;

namespace Traceability_Management.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Processiings_TwoWayAllController : ControllerBase
    {
        IMediator mediator;

        public Processiings_TwoWayAllController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        [HttpPost]
        public async Task<ApiResult<int>> AddTwoWayAll(Processiings_Two Processiings_Two)
        {
            try
            {
                AddTwoWayCommand AddTwoWayCommand = new AddTwoWayCommand()
                {
                    Processiings_Two = Processiings_Two
                };
                return await mediator.Send(AddTwoWayCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [HttpGet]
        public async Task<ApiResult<Processiings_Two>> FirstNextSlaughts([FromQuery] FirstTwoWayCommand FirstTwoWayCommand)
        {
            try
            {
                return await mediator.Send(FirstTwoWayCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [HttpPost]
        public async Task<ApiResult<int>> UpdateNextSlaughts(Processiings_Two Processiings_Two)
        {
            try
            {
                UpdateTwoWayCommand UpdateTwoWayCommand = new UpdateTwoWayCommand()
                {
                    Processiings_Two = Processiings_Two
                };
                return await mediator.Send(UpdateTwoWayCommand);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
